<?php
ob_start();
error_reporting(E_ALL ^ E_NOTICE);
session_start();
$_SESSION['madv'] = $_POST['tendv'];
$_SESSION['mansx'] = $_POST['nhasx'];
$_SESSION['namsx'] = $_POST['nsx'];
$_SESSION['maloai'] = $_POST['loaimay'];

include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/configs/database.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/controls/c_thongKe.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/libraries/PHPExcel_1.7.9_doc/Classes/PHPExcel.php');
?>

<html>
    <head>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Demo Ajax</title>
        <link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
        <script type="text/javascript" src="/htqlmba/views/v_javascript_tc.js"></script>
    </head>
    <body>
        <form name="formthongkesx" method="post" action="">
            <table align="center" class="TableField2" width="590" border="0">
                <tr>
                    <td align=center class="TableHeader1"> &equiv; Thống kê tùy chọn</td>
                </tr>
                <tr >
                    <td bgcolor="#dae9f3">
                        <table width="590" border="0" align="center">
                            <tr>
                                <td height="5px" colspan="2">&nbsp;</td>
                            </tr>
                            <!--Sua tai day: them vao-->
                    <?php
                            
                            $db = new database();
							$db->setQuery("select * from don_vi as dv, tai_khoan as tk where dv.MA_DON_VI = tk.MA_DON_VI and tk.MA_DON_VI = ".$_SESSION['nmadv']);
							$result = $db->fetchAll();			
			 				$row = mysql_fetch_array($result);
			 				if ($row['QUYEN'] == 2 || $row['QUYEN']==1){
                            echo "<tr>";
                               echo "<td width='120' align='right' class='TableField2'>Đơn Vị: </td>";
                                echo "<td width='200' align='left'>";
                                    
                                   echo "<select name='tendv' id='mdv' style='width: 200px'>";
                                     echo  " <option value='tatca'>Tất cả</option>";
                                        $db->setQuery("select * from don_vi as dv, tai_khoan as tk where dv.MA_DON_VI = tk.MA_DON_VI  and tk.QUYEN = 3");

                                        $result = $db->fetchAll();

                                        while ($row = mysql_fetch_array($result)) {

                                            echo "<option value=\"" . $row['MA_DON_VI'] . "\">" . $row['TEN_DON_VI'] . "</option>";        
											
											
											
											
											}
											
                                 echo " </select>";                                    
                                echo "</td>";
							    echo "</td>";
                                echo "<td width='120' align='right' class='TableField2'>Nhà Sản Xuất: </td>";
                                echo "<td width='200' align='left'>";
                                echo "<select name='nhasx' id='nhasx'>";
                                 echo "<option value='tatca'>Tất cả</option>";
 
                                        $db = new database();
                                        $db->setQuery("select * from nha_sx");
                                        $re = $db->fetchAll();

                                        while ($row = mysql_fetch_array($re)) {
                                            echo "<option value=\"" . $row['MA_NSX'] . "\">" . $row['TEN_NSX'] . "</option>";
                                        }

                                    echo "</select>";
                               echo " </td>";
                            echo "</tr>";
							}
							   else {
                            echo "<input type='hidden' id='mdv' name='tendv' value='".$row['MA_DON_VI']."'/>";
                            		echo "<tr>";         

                                echo "<td width='120' align='right' class='TableField2'>Nhà Sản Xuất: </td>";
                                	echo "<td width='200' align='left'>";
                                	echo "<select name='nhasx' id='nhasx'>";
                                 	echo "<option value='tatca'>Tất cả</option>";
 
                                        $db = new database();
                                        $db->setQuery("select * from nha_sx");
                                        $re = $db->fetchAll();

                                        while ($row = mysql_fetch_array($re)) {
                                            echo "<option value=\"" . $row['MA_NSX'] . "\">" . $row['TEN_NSX'] . "</option>";
                                        }

                                    echo "</select>";
                               echo " </td>";
                            echo "</tr>";	


									}
                                        ?>

                            <!--Het sua-->
                            <tr>
                                <td width="120" align="right" class="TableField2">Năm Sản Xuất: </td>
                                <td width="200" align="left">
                                    <select name="nsx" id="nsx">
                                        <option value="tatca"\">Tất cả</option>;
                                        <?php
                                        $db = new database();
                                        $db->setQuery("select * from may_bien_ap group by NAM_SX");
                                        $re = $db->fetchAll();
                                        while ($row = mysql_fetch_array($re)) {

                                            echo "<option value=\"" . $row['NAM_SX'] . "\">" . $row['NAM_SX'] . "</option>";
                                        }
                                        ?>
                                    </select>
                                </td>

                                <td width="120" align="right" class="TableField2">Loại Máy: </td>
                                <td width="200" align="left">
                                    <select name="loaimay" id="loaimay">
                                        <option value="tatca"\">Tất cả</option>;
                                        <?php
                                        $db = new database();
                                        $db->setQuery("select * from loai_may");
                                        $re = $db->fetchAll();
                                        while ($row = mysql_fetch_array($re)) {

                                            echo "<option value=\"" . $row['MA_LOAI'] . "\">" . $row['TEN_LOAI'] . "</option>";
                                        }
                                        ?>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <td height="5px" colspan="4">&nbsp;</td>
                            </tr>
                            <tr>
                                <td colspan="4" align="center">
                                    <input type="button" value="Thống kê" onClick="thongke()">
                                    &nbsp;&nbsp;

                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <br>	
            <!-- Dưới đây là định vị cái chỗ để kết quả xuất hiện -->
            <div id="xuathienchonay"> </div>
        </form>
    </body>
</html>